<?php
JavaScript::deleteItem();

$this->breadcrumbs=array(
	Yii::t('yii','Users'),
	$user->username,
);

if (Yii::app()->user->hasAuth(Group::ADMIN)){
	$this->menu[] = array('Списък с потребители', array('list'));
	$this->menu[] = array('Редактиране', array('update','id'=>$user->id),);
	$this->menu[] = array('Изтриване', array('delete','id'=>$user->id), 'htmlOptions'=>array('class' => 'deleteItem'));
}

$username = Html::encode($user->username); //cache the encoding

if(!Yii::app()->user->isGuest){
		$models = Userdata::model()->find('user = '.Yii::app()->user->id);

		if(is_array($models->friends) && in_array($data->id,json_decode($models->friends))){
			$id = "liked"; 
			$text = "Премахни от контакти";
		}else{	
			$id = "liking";
			$text = "Добави към контакти";
}	
?><a class="<?php echo $id; ?> static" href="#"  onclick="return false;"><?php echo $text; ?></a>
<?php } ?>
<div stype="height:500px;">
<h2>Профил на <?php echo $username ?></h2>

<p>
	Регистриран на <b><?php echo Time::nice($user->created, 'd.m.y'); ?></b>
	<?php if ($user->email_visible) {?>
		<br />Email: <b><?php echo $user->email ?></b>
	<?php } ?>
	<br />Написал е <?php echo $user->num_posts;?> статии
</p>
<?php if (!empty($user->about)) { ?>
	<h3>Описание <?php echo $username; ?></h3>
	<?php echo $user->getMarkdown('about'); ?>
</div>
<div style="clear:both"></div>
<?php }
if (!empty($posts)) {
?>

<h4>Блог публикации от <?php echo $username; ?></h4>
<?php
foreach($posts as $n=>$post){ ?>
<div class="post">
<h3><?php echo Html::link($post->title,array('blog/view','id'=>$post->id)); ?></h3>
<?php echo mb_substr(strip_tags($post->content),0,600,'UTF-8').".......";; ?>
</div>
<?php }
$this->widget('CLinkPager',array('pages'=>$pages));
?>
<?php } ?>

<script type="text/javascript">

$('a.liking').toggle(function() {
  $(this).text('Премахни от контакти');
  $.get("/system/friend/id/<?php echo $user->id; ?>");
}, function() {
  $(this).text('Добави към контакти');
  $.get("/system/friend/id/<?php echo $user->id; ?>");
});

$('a.liked').toggle(function() {
  $(this).text('Добави към контакти');
  $.get("/system/friend/id/<?php echo $user->id; ?>");
}, function() {
  $(this).text('Премахни от контакти');
  $.get("/system/friend/id/<?php echo $user->id; ?>");
});


</script>
